import React, { useEffect, useState } from "react";
import { getHospitalDetailRequest } from "@api/hospital/hospitalList";
import { useNavigate, useParams } from "react-router-dom";
import { getHospitalDetailType } from "@/api/hospital/model/hospitalListTypes";
import { Descriptions, Card, Button } from "antd";

export default function HospitalShow() {
  const { id } = useParams();
  const navigate=useNavigate()

  const [hosDetail, setHosDetail] = useState<getHospitalDetailType>({});
  useEffect(() => {
    const getHosDetail = async () => {
      const re = await getHospitalDetailRequest(id as string);
      setHosDetail(re);
    };
    getHosDetail();
  }, []);
  return (
    <div>
      <Card>
        <Descriptions title="基本信息" bordered column={2}>
          <Descriptions.Item label="医院名称">
            {hosDetail.hospital?.hosname}
          </Descriptions.Item>

          <Descriptions.Item label="医院Logo">
            {hosDetail.hospital?.logoData ? (
              <img
                width={200}
                src={`data:image/jpeg;base64,${hosDetail.hospital?.logoData}`}
              />
            ) : (
              ""
            )}
          </Descriptions.Item>

          <Descriptions.Item label="医院编号">
            {hosDetail.hospital?.hoscode}
          </Descriptions.Item>

          <Descriptions.Item label="医院地址">
            {hosDetail.hospital?.address}
          </Descriptions.Item>

          <Descriptions.Item label="医院坐车路线" span={2}>
            {hosDetail.hospital?.route}
          </Descriptions.Item>

          <Descriptions.Item label="医院简介" span={2}>
            {hosDetail.hospital?.intro}
          </Descriptions.Item>
        </Descriptions>
        <Descriptions style={{marginTop:30}} title="预约规则信息" bordered column={2}>
          <Descriptions.Item label="预约周期">
            {hosDetail.bookingRule?.cycle}
          </Descriptions.Item>
          <Descriptions.Item label="放号时间">
            {hosDetail.bookingRule?.releaseTime}
          </Descriptions.Item>
          <Descriptions.Item label="停挂事件">
            {hosDetail.bookingRule?.quitTime}
          </Descriptions.Item>
          <Descriptions.Item label="停号时间">
            {hosDetail.bookingRule?.stopTime}
          </Descriptions.Item>
          <Descriptions.Item label="预约规则" span={2}>
            {hosDetail.bookingRule?.rule.map((item,index)=>{
              return <p key={index}>{item}</p>
            })}
          </Descriptions.Item>
        </Descriptions>

        <Button style={{marginTop:30}} onClick={()=>{navigate(-1)}}>返回</Button>
      </Card>
    </div>
  );
}
